package com.easy.project.controller.system;

import cn.hutool.core.collection.ListUtil;
import com.easy.project.base.result.BizResult;
import com.easy.project.domain.dto.system.MenuEditDTO;
import com.easy.project.domain.dto.system.UserEditDTO;
import com.easy.project.domain.vo.system.SysMenuVO;
import com.easy.project.service.system.ISysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.compress.utils.Lists;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 系统菜单表 前端控制器
 * </p>
 *
 * @author wxz
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/sys-menu-po")
@Api(tags = "系统管理-菜单管理")
public class SysMenuController {

    @Resource
    private ISysMenuService sysMenuService;


    /**
     * 根据角色获取菜单
     * @return
     */
    @GetMapping("/role/menu")
    @ApiOperation(value = "根据角色id获取菜单")
    public BizResult<List<SysMenuVO>> roleMenu(@RequestParam Long roleId){
        return BizResult.success(sysMenuService.getMenuByRoleId(Collections.singletonList(roleId)));
    }

    /**
     * 获取所有菜单
     * @return
     */
    @GetMapping("/all/menu")
    @ApiOperation(value = "获取所有菜单")
    public BizResult<List<SysMenuVO>> allMenu(){
        return BizResult.success(sysMenuService.allMenu());
    }

    /**
     * 编辑菜单
     * @param menuEditDTO
     * @return
     */
    @PostMapping("/menu/edit")
    @ApiOperation(value = "编辑菜单",notes = "编辑菜单 有id更新 无id新增")
    public BizResult<Void> menuEdit(@RequestBody @Validated MenuEditDTO menuEditDTO){
        sysMenuService.menuEdit(menuEditDTO);
        return BizResult.success();
    }
}
